
#include "exynos_4412.h"
/*
 *
 * 编程实现通过LED状态显示当前电压范围
 * 1501-1800mv  LED2 LED3 LED4 LED5点亮
 * 1001-1500mv LED2 LED3 LED4 点亮
 * 501-1000mv LED2 LED3点亮
 * 0-500mv  LED2闪烁
 */
void Delay(unsigned int Time){
	while(Time--);
}

int main()
{
	unsigned int AdcValue;

	/*设置ADC精度为12bit*/
	ADCCON = ADCCON | (1 << 16);
	/*使能ADC分频器*/
	ADCCON = ADCCON | (1 << 14);
	/*设置ADC分频值 ADC时钟频率=PLCK/(19+1)=5MHZ ADC转换频率=5MHZ/5=1MHZ*/
	ADCCON = ADCCON & (~(0xFF << 6)) | (19 << 6);
	/*关闭待机模式，使能正常模式*/
	ADCCON = ADCCON & (~(1 << 2));
	/*关闭通过读使能AD转换*/
	ADCCON = ADCCON & (~(1 << 1));
	/*选择转换通道，3通道*/
	ADCMUX = 3;

	//控制LED2
	GPX2.CON = GPX2.CON & (~(0xF << 28)) | (0x1 << 28);
	//控制LED3
	GPX1.CON = GPX1.CON | 1;
	//控制LED4
	GPF3.CON = GPF3.CON | (1 << 16);
	//控制LED5
	GPF3.CON = GPF3.CON | (1 << 20);

	while(1)
	{
		/*开始转换*/
		ADCCON = ADCCON | 1;
		/*等待转换完成*/
		while(!(ADCCON & (1 << 15)));
		/*读取转换结果*/
		AdcValue = ADCDAT & 0xFFF;
		/*将结果转换成实际的电压值mv*/
		AdcValue = AdcValue * 0.44;
		if(AdcValue >= 1501 && AdcValue <= 1801){
			//LED2 LED3 LED4 LED5均点亮
			/*点亮LED2*/
			GPX2.DAT = GPX2.DAT | (1 << 7);
			/*点亮LED3*/
			GPX1.DAT = GPX1.DAT | 1;
			/*点亮LED4*/
			GPF3.DAT = GPF3.DAT | (1 << 4);
			/*点亮LED5*/
			GPF3.DAT = GPF3.DAT | (1 << 5);
		}else if(AdcValue >= 1001 && AdcValue <= 1500){
			//LED2 LED3 LED4点亮
			/*点亮LED2*/
			GPX2.DAT = GPX2.DAT | (1 << 7);
			/*点亮LED3*/
			GPX1.DAT = GPX1.DAT | 1;
			/*点亮LED4*/
			GPF3.DAT = GPF3.DAT | (1 << 4);
			/*熄灭LED5*/
			GPF3.DAT = GPF3.DAT & (~(1 << 5));
		}else if(AdcValue >= 501 && AdcValue <= 1000){
			//LED2 LED3点亮
			/*点亮LED2*/
			GPX2.DAT = GPX2.DAT | (1 << 7);
			/*点亮LED3*/
			GPX1.DAT = GPX1.DAT | 1;
			/*熄灭LED4*/
			GPF3.DAT = GPF3.DAT & (~(1 << 4));
			/*熄灭LED5*/
			GPF3.DAT = GPF3.DAT & (~(1 << 5));
		}else {
			//LED2闪烁
			/*熄灭LED3*/
			GPX1.DAT = GPX1.DAT & (~1);
			/*熄灭LED4*/
			GPF3.DAT = GPF3.DAT & (~(1 << 4));
			/*熄灭LED5*/
			GPF3.DAT = GPF3.DAT & (~(1 << 5));
			/*点亮LED2*/
			GPX2.DAT = GPX2.DAT | (1 << 7);
			/*延时*/
			Delay(1000000);
			/*熄灭LED2*/
			GPX2.DAT = GPX2.DAT & (~(1 << 7));
			/*延时*/
			Delay(1000000);
		}
	}
	return 0;
}
